package edu.misaka.moe.service;

import java.util.List;
import java.util.Map;

import edu.misaka.moe.dao.HobbyDaoImpl;
import edu.misaka.moe.domain.Hobby;
import edu.misaka.moe.service.iface.HobbyService;

public class HobbyServiceImpl  implements HobbyService{

	HobbyDaoImpl hd=new HobbyDaoImpl();
	@Override
	public List<Hobby> getHobbies() {
		return hd.getHobbies();
		
	}

	//把list中的爱好编码转换成中文表示
		public void setHobbyName(List<Map<String, Object>> list) {
			List<Hobby> hobbies=hd.getHobbies();
			list.forEach((map)->{
				String temp=(String) map.get("HOBBY_CODE");
				for(Hobby hobby:hobbies) {
					if(null==temp) {
						temp="这个人很懒，没有爱好...";
					}else if(temp.indexOf(hobby.getCode())!=-1){
						temp=temp.replace(hobby.getCode(), hobby.getName());
					}
				}
				map.put("HOBBY_CODE", temp);
			});
		}
	@Override
	public List<Hobby> getHobbiesSelected(String selected) {
		List<Hobby> list=hd.getHobbies();
		list.stream().filter((item)->selected.indexOf(item.getCode())!=-1)
			.forEach((item)->item.setSelected(true));
		
		return list;
	}
				
}
